class MyPage extends BaseList {
    constructor(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl) {
        super(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl);
    }
    SetCriterion(item) {
        item['Begin'] = $.trim($('#Begin').val()) === '' ? null : $.trim($('#Begin').val());
        item['End'] = $.trim($('#End').val()) === '' ? null : $.trim($('#End').val());
        item['SupplierNameFilterValue'] = $.trim($('#SupplierNameFilterValue').val()) === '' ? null : $.trim($('#SupplierNameFilterValue').val());
        return item;
    }
    GetFilter(pageIndex) {
        let item = super.GetFilter(pageIndex);
        // 设置条件
        item = this.SetCriterion(item);
        return JSON.stringify(item);
    }
    FetchAll() {
        $("#Begin").val("");
        $("#End").val("");
        $("#SupplierNameFilterValue").val("");
        this.$pagination.attr("_msh_page", 1);
        this.FetchForPage(1);
    }
    EmptyTableContent() {
        $("#tabData01 tbody").empty();
        this.$pagination.attr("_msh_page", 1);
    }
    SetTableContent(result) {
        $("#tabData01 tbody").empty();
        let content_01 = '';
        for (let i = 0; i < result.length; i++) {
            content_01 = '<tr _mash_id="' + result[i].headerId + '">';
            content_01 += '<td class="column__action"><span title="编辑" class="edit" onclick="_Instance.DoEdit($(this))"><i class="fa-all fa-pencil fa-1"></i></span></td>';
            if (result[i].checkedBy !== null) {
                content_01 += '<td></td>';
            } else {
                // 删除权限控制
                if ($("#ActionAcl_4").length === 0 || parseInt($("#ActionAcl_4").val() === 0)) {
                    content_01 += '<td></td>';
                } else {
                    content_01 += '<td class="column__action"><span title="删除" class="trash" onclick="_Instance.DoDelete($(this));"><i class="fa-all fa-trash-o fa-1"></i></span></td>';
                }
            }
            content_01 += '<td>' + formatNullData(result[i].billNo) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].supplierName) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].cycleOfBillFrom) + '（至）' + formatNullData(result[i].cycleOfBillTo) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].yearOfBill) + '、' + formatNullData(result[i].monthOfBill) + '</td>';
            //content_01 += '<td>' + formatNullData(result[i].tuckingCost) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].updatedByName) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].updatedDate) + '</td>';
            content_01 += '<td style="border-right: none;">' + formatNullData(result[i].description) + '</td>';
            content_01 += '</tr>';

            $("#tabData01 tbody").append(content_01);
            content_01 = '';
        }
        setOneTableRowColor("tabData01");
    }
    DoInsert() {
        super.DoInsert();
        location.assign(parent.basePath + '/purchase/notes_payabled/1/0/edit.html');
    }
    DoEdit($self) {
        super.DoEdit();
        // 设置当前检索后的数据列表标识数组
        let _arrayResultList = new Array();
        $("#tabData01 tbody tr").each(function (index) {
            _arrayResultList.push($(this).attr("_mash_id"));
        });
        $.cookie(this.cokieListResult, _arrayResultList.join(","));
        location.assign(parent.basePath + '/purchase/notes_payabled/2/' + $self.parent().parent().attr("_mash_id") + '/edit.html');
    }
    DoDelete($self) {
        let _params = super.GetFilter(this.$pagination.attr("_msh_page"));
        // 设置条件
        _params = this.SetCriterion(_params);
        _params['HeaderId'] = $self.parent().parent().attr("_mash_id");
        _params['DeletedBy'] = $("#UserId").val();
        _params['DeletedBillNo'] = $self.parent().parent().find("td").eq(2).text();

        super.DoDelete(_params, function (_this, data) {
            if (data.Success === true) {
                _this.BuildDataTable(data);
            } else {
                _this.EmptyTableContent();
            }
            ShowSuccessMessagePanel("删除成功。");
        });
    }
    SaveFilters() {
        let _filters = new Array();
        _filters.push($("#Begin").val());
        _filters.push($("#End").val());
        _filters.push($("#SupplierNameFilterValue").val());
        $.cookie("notes_payabled_list_fiters", _filters.join(","));
    }
    RestoreFilters() {
        if ($.cookie("notes_payabled_list_fiters") !== undefined) {
            let _filters = $.cookie("notes_payabled_list_fiters").split(',');
            $("#Begin").val(_filters[0]);
            $("#End").val(_filters[1]);
            $("#SupplierNameFilterValue").val(_filters[2]);
        } else {
            $("#Begin").val("");
            $("#End").val("");
            $("#SupplierNameFilterValue").val("");
        }
    }
}

//-----------------------------------------------------------------------------
// 定义实例
//-----------------------------------------------------------------------------
let _Instance = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    let flag = jQuery.url.param("flag") === undefined ? 0 : jQuery.url.param("flag");
    // 默认初始化每页显示15条数据
    $("#page-size").val($.cookie("notes_payabled_list_pagesize") === undefined ? 15 : $.cookie("notes_payabled_list_pagesize"));
    // 删除已经保存的检索后的数据列表标识数组
    $.cookie("notes_payabled_list_result", null);

    _Instance = new MyPage(0, null, flag,
            $("#page-size"),
            $("#page_indicator_block"),
            "notes_payabled_list_pagesize",
            "notes_payabled_list_pageindex",
            "notes_payabled_list_result",
            "/purchase/notes_payabled/header/fetchForPage.html",
            "/purchase/notes_payabled/header/delete.html");

    // 设置分页控制 （操作区域）
    $("#wrapper__navbar").swPagination({
        link_string: '/?page={page_number}',
        max_page: null,
        paged: function (page) {
            $("#page_indicator_block").attr("_msh_page", page);
            _Instance.FetchForPage(page);
        }
    });
    /*
     // 设置表格排序字段
     $("#tabHeader01").wxTableSorter({
     sortList: [[4, 1]], // 第一个表示列的序号，第二个表示排序种类
     headers: {4: {sorter: false}},
     columnList: [[1, "H.DateOfContract"]],
     detailList: $("#tabData01"),
     sort: sortTable
     });
     */
    window.laydate.render({
        elem: '#Begin',
        theme: '#393D49',
        trigger: 'click'
    });
    window.laydate.render({
        elem: '#End',
        theme: '#393D49',
        trigger: 'click'
    });
    _Instance.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
}